<body leftmargin="0" rightmargin="0" topmargin="0">
<!--application header-->
<? include "header.inc.php"; ?>
<!--EOapplication header-->

<? if ($USE_FRAME_MENU == false) { ?>
<!--left menu start-->
<div style="float: left; width:180px; height:100%; margin-right:20px;">
<?
include "menu.inc.php";
?>
</div>
<!--left menu end-->
<? } ?>

<!--Main start here-->
<div id="main" style=" margin-left:20px;" align="">
<form name="form" action="?act=approve_outing" id="daftar" method="post" onSubmit="return GoSubmit(this)">
  <br>
  <table width="750" border="0" cellpadding="2" cellspacing="0" class="tableMainBodyFont">
    <tbody>
      <tr>
        <td width="3%" align="center" bgcolor="#aaaaaa" style=" border-top-style:solid;border-top-width:1px;"><strong>Senarai Pengguna Sistem </strong></td>
      </tr>
    </tbody>
  </table>
  <table width="750" class="tableMainBodyFont">
    <tr>
      <td>
	    <a href="?act=user_list"><strong>Semua(<?=pg_numrows($alls)?>)</strong></a> 
	  | <a href="?act=user_list&role=2">Warden(<?=pg_numrows($wardens)?>)</a>
	  | <a href="?act=user_list&role=3">HEP(<?=pg_numrows($heps)?>)</a>
	  | <a href="?act=user_list&role=4">Pengawal(<?=pg_numrows($guards)?>)</a></td>
      <td align="right"><a href="?act=new_user" style="color:blue; font-size:10px;">Tambah</a></td>
    </tr>
  </table>
  <table width="750" border="1" bgcolor="#dddddd" class="tableMainBodyFont" id="qua_table">
    <tr style=" border-bottom-style:dashed; border-bottom-width:thin;">
      <th width="15">Bil.</th>
      <th width="15%">ID Pengguna </th>
      <th width="">Peranan </th>
      <th width="">&nbsp;</th>
    </tr>
    <?
	$bil = 0;
    while ($user = pg_fetch_array($users)) {
		if ($user[id] == 1) continue;
		$bil++;
		$user_roles = "SELECT * FROM users_roles as ur INNER JOIN roles as r ON r.id=ur.role_id".
		              " WHERE user_id=".$user['id'];
		$user_roles = pg_query($user_roles);
		$joined_roles = array();
		while ($d = pg_fetch_array($user_roles)) {
			$joined_roles[] = $d['name'];
		}
		if (sizeof($joined_roles) > 0) 
			$joined_roles = join(",",$joined_roles);	  
		else
			$joined_roles = "&nbsp;";
    ?>
    <tr align="center" id="<?="row_$i"?>">
      <td align="center"><?=$bil?></td>
      <td align="left">&nbsp;
        <?=$user[username]?>
      </td>
      <td align="center"><?=$joined_roles?></td>
      <td><a href="?act=edit_user&id=<?=$user[id]?>" style="color:blue; font-size:10px;">Edit</a> | <a href="javascript: confirmDelete(<?=$user[id]?>);" style="color:blue; font-size:10px;">Padam</a> </td>
    </tr>
    <?
	  }
	  ?>
  </table>

  </form>

<!--Main end here-->
</div>
</body>
<script>
function GoSubmit(df) {
	
	if (!checkInput(icnumRegExp,document.getElementById('ic_new'),'No Kad Pengenalan Baru')) return false;
	//if (!checkInput(anythingRegExp,$('name'),'Nama Staf')) return false;
	//if (!checkSelection(strRegExp,document.getElementById('gender'),'Jantina')) return false;
	return true;
}

</script>

<script>
function checkAll(df) {
  for (i=1; i<df.elements.length; i++ )
  {
     if (df.elements[i].type == "checkbox")
     {
       df.elements[i].checked = df.checkall.checked
     } 
  }
}

function confirmDelete(userid) {
	if(confirm("Adakah anda pasti?")) {
		location = '?act=destroy_user&id=' + userid;
	}
	else return;
}
</script>

<? alert_some_message();?>
